<?php

namespace App\Listeners\Subscriber;

use Illuminate\Events\Dispatcher;
use App\Jobs\AttendanceReportGenerate;
use App\Events\Attendance\CreatedEvent;
use Illuminate\Contracts\Queue\ShouldQueue;

/**
 * 考勤数据模型订阅者
 *
 * Date: 09/05/2018
 * @author George
 * @package App\Listeners\Subscriber
 */
class AttendanceEventSubscriber implements ShouldQueue
{
	/**
	 * 当考勤记录创建成功后分发任务
	 *
	 * Date: 09/05/2018
	 * @author George
	 * @param CreatedEvent $event
	 * @throws \Throwable
	 */
	public function onCreated(CreatedEvent $event)
	{
		AttendanceReportGenerate::dispatch($event->attendance);
	}

	/**
	 * 为订阅者注册监听器
	 *
	 * Date: 23/03/2018
	 * @author George
	 * @param Dispatcher $events
	 */
	public function subscribe(Dispatcher $events)
	{
		$events->listen(
			'App\Events\Attendance\CreatedEvent',
			'App\Listeners\Subscriber\AttendanceEventSubscriber@onCreated'
		);
	}
}
